package com.liangtian.mdm.base.handler;


import com.liangtian.mdm.base.response.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import static com.liangtian.mdm.base.constants.ResultCode.FAIL_NO_PERMISSION;

/**
 * @author wx
 */
@Slf4j
@RestControllerAdvice
@Order(value = Ordered.HIGHEST_PRECEDENCE)
public class GlobalExceptionHandler {


    @ExceptionHandler(value = UnauthorizedException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public BaseResponse handleUnauthorizedException(Exception e) {
        log.error("权限不足，{}", e.getMessage());
        return BaseResponse.genResponse(FAIL_NO_PERMISSION);
    }
}
